package com.example.foo.api.web.account;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import com.ruoyi.common.core.domain.AjaxResult;
import com.example.foo.account.service.AccountService;
import com.example.foo.api.boot.TokenHelper;

@org.springframework.web.bind.annotation.RestController
public class AccountAction {

	private final AccountService accountService;

	public AccountAction(AccountService accountService) {
		this.accountService = accountService;
	}

	@GetMapping("/api/accounts/userId={userId}/summary")
	public AjaxResult showAccount(@PathVariable("userId") Long userId) {
		Long loginedUserId = TokenHelper.verifyToken();
		if (!Objects.equals(userId, loginedUserId)) {
			return AjaxResult.error(403, "Access Forbidden");
		}
		Map<String, BigDecimal> accountSummaryMap = accountService.findAccountSummaryAsMapByUserId(userId);
		return AjaxResult.successData(accountSummaryMap);
	}

}
